<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
</head>

<body>
    <input type="text" id="text">
</body>
<script type="text/javascript">
    var text = document.getElementById("text");
    var arrMg = ['sb', 'md', 'bt'];
    text.addEventListener('change', function() {
        var a = text.value;
        for (var i = 0; i < arrMg.length; i++) {
            var reg = new RegExp(arrMg[i], 'gi');
            if (a.indexOf(arrMg[i]) != -1) {
                var b = a.replace(reg, '**');
                a = b;
            }
        }
        console.log(a);
    });

    var str = 'This is a Box box Box!';
    var reg = /\bbox/g;
    console.log(reg.exec(str));
    console.log(reg.test(str));
</script>

</html>